package com.bff.gaia.client.combine;

import com.bff.gaia.api.common.Plan;

import java.io.*;
import java.util.List;

public class MergePlan {
	public void getPlans(List<String> filePath, List<Plan> plans) {// 从本地文件中获取序列化的Plan，并将其放入list集合中
		Plan plan = null;
		ObjectInputStream os = null;
		try {
			for (String file : filePath) {
				os = new ObjectInputStream(new FileInputStream(new File(file)));
				plan = (Plan) os.readObject();
				os.close();
				plans.add(plan);
			}
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			System.out.println("获取Plan 集合失败。");
		}
	}

	//序列化plan到本地文件
	public void serializePlan(Plan plan, String filePath) {
		ObjectOutputStream oos = null;
		try {
			oos = new ObjectOutputStream(new FileOutputStream(new File(filePath)));
			oos.writeObject(plan);
			oos.close();
		} catch (IOException e) {
			System.out.println("序列化Plan失败");
		}
	}
}